import pymysql

# 创建与数据库的连接
db = pymysql.connect(
    host="192.168.122.203",
    user="root",
    password="root",
    database="testdb",
    port=3307,  # 指定端口号
)

# 创建游标对象cursor
cursor = db.cursor()

# 将sno=3的学生成绩修改为99.5
sql = "update student set score=%s where sno=%s"

try:
    # 执行sql
    cursor.execute(sql, (99.5, 3))
    # 提交数据
    db.commit()
    print("修改成功")
except Exception as e:
    print(e)
    # 如果出现异常，回滚
    db.rollback()
    print("修改失败")
finally:
    # 关闭数据库连接
    db.close()
